package com.litelimit.autoconfigure.configure;

import com.litelimit.core.service.listener.LuaListener;
import com.litelimit.core.service.loader.LuaScriptLoader;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * lua脚本
 */
@Configuration
@AllArgsConstructor
public class LuaConfiguration {

    private final StringRedisTemplate stringRedisTemplate;

    @Bean
    @ConditionalOnMissingBean(LuaScriptLoader.class)
    public LuaScriptLoader luaScriptLoader(){
        return new LuaScriptLoader(stringRedisTemplate);
    }

    @Bean
    @ConditionalOnMissingBean(LuaListener.class)
    public LuaListener listener(){
        return new LuaListener(stringRedisTemplate);
    }
}
